package cn.chenxhcloud.myvv;

import java.nio.ByteBuffer;

import org.voovan.network.IoHandler;
import org.voovan.network.IoSession;
import org.voovan.tools.log.Logger;

@SuppressWarnings("all")
public class ClientHandler implements IoHandler {

    
    public Object onConnect(IoSession session) {
        Logger.simple("onConnect");
        session.setAttribute("key", "attribute value");
        String msg = new String("test message\r\n");
        return msg;
    }

    
    public void onDisconnect(IoSession session) {
        Logger.simple("onDisconnect");
    }

    
    public Object onReceive(IoSession session, Object obj) {
        //+"["+session.remoteAddress()+":"+session.remotePort()+"]"
        Logger.simple("Client onRecive: "+obj.toString());
        Logger.simple("Attribute onRecive: "+session.getAttribute("key"));
        session.close();
        return obj;
    }

    public void onException(IoSession session, Exception e) {
        Logger.simple("Client Exception");
        Logger.error(e);
        session.close();
    }

    public void onSent(IoSession session, Object obj) {
        ByteBuffer sad = (ByteBuffer)obj;
        sad = (ByteBuffer)sad.rewind();
        Logger.simple("Client onSent: "+new String(sad.array()));
    }

	public void onIdle(IoSession session) {
		// TODO Auto-generated method stub
		
	}
}